﻿#region

using System.IO;
using MediaSage.Lib.Configuration;
using MediaSage.Lib.Database;
using MediaSage.Lib.Plugin.FileNameProvider;
using Microsoft.VisualStudio.TestTools.UnitTesting;

#endregion

namespace MediaSageLibTest
{
    using MediaSage.Lib.Plugin.TVDBProvider;
    using MediaSage.Lib.Plugin.FileNameProvider;

    [TestClass]
    public class PluginManagerTest
    {
        #region Fields

        private static Config config;

        #endregion Fields

        #region Constructors

        public PluginManagerTest()
        {
            config = new Config();
        }

        #endregion Constructors

        #region Methods

        [TestMethod]
        [DeploymentItem("FileNameProvider.Dll", "TestData")]
        public void LoadPlugin()
        {
            var pe = new PluginEntity();
            pe.Location = Path.Combine(Directory.GetCurrentDirectory(), @"TestData\FileNameProvider.dll");
            pe.Name = "FileNameProvider";
            var FNP = (FileNameProvider) config.PluginManager.GetPlugin(pe);
            VersionInfo vi = FNP.GetVersionInfo();
            Assert.AreEqual(vi.MajorVersion,0);
            Assert.AreEqual(vi.MinorVersion,9);
        }

        [TestMethod]
        [DeploymentItem("TVDBProvider.dll")]
        public void LoadPlugin2()
        {
            var pe = new PluginEntity();
            pe.Location = Path.Combine(Directory.GetCurrentDirectory(), @"TVDBProvider.dll");
            pe.Name = "TVDBProvider.dll";
            var FNP = (TVDBProvider)config.PluginManager.GetPlugin(pe);
            VersionInfo vi = FNP.GetVersionInfo();
            Assert.AreEqual(vi.MajorVersion, 0);
            Assert.AreEqual(vi.MinorVersion, 9);
        }


        [TestMethod]
        [DeploymentItem("FileNameProvider.Dll", "TestData")]
        public void UnloadPlugin()
        {
            var pe = new PluginEntity();
            pe.Location = Path.Combine(Directory.GetCurrentDirectory(), @"TestData\FileNameProvider.dll");
            pe.Name = "FileNameProvider";
            var FNP = (FileNameProvider) config.PluginManager.GetPlugin(pe);

            config.PluginManager.UnloadPlugin(pe);
            // Try to delete the file
            File.Delete(pe.Location);
        }

        #endregion Methods
    }
}